<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="Note.vo.Page" %>
<%--
  Created by IntelliJ IDEA.
  User: 王宇航
  Date: 2022/4/16
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<head>
    <title>Title</title>
</head>
<body>
<script>

    function deleteNote(id){
if (confirm("确定删除吗?")){
    location.href="${pageContext.request.contextPath}/DeleteNoteServlet?from=1&id="+id;
}
    }
</script>
<form action="${pageContext.request.contextPath}/QueryNoteByPageServlet" class="form-inline">
    <ul class="nav  nav-tabs">
        <li role="presentation" class="active"><a href="#">主页</a></li>
        <li role="presentation"><a href="${pageContext.request.contextPath}/QueryNoteServlet">显示所有留言</a></li>
        <li role="presentation"><a href="${pageContext.request.contextPath}/user/insertNotes.jsp">添加留言</a>
        <li role="presentation"><img src="../images/${requestScope.imageSrc}" alt="加载中" title="头像" width="32" height="32"></li>
        <li role="presentation" class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
                ${sessionScope.name} <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li role="presentation" ><a href="${pageContext.request.contextPath}/user/updateImage.jsp">修改头像</a></li>
            </ul>
        </li>
        <li role="presentation" ><a href="${pageContext.request.contextPath}/quitServlet?id=0"><img src="../images/quit.png" width="23" height="23" alt="退出" title="退出"></a></li>
    </ul>
    <h1 style="color: chocolate" align="center">JSP学习论坛留言版
    </h1><br><br>
    <p align="center">
        <label>Title</label><input type="text" name="title" class="form-control" value="${condition.title[0]}">
        <label>Author</label><input type="text" name="author" class="form-control" value="${condition.author[0]}">
        &nbsp;<button id="search" type="submit" class="btn btn-default">搜索</button>
    </p>
</form>
<table class="table table-bordered table-striped table-hover">
    <tr style="background: skyblue" class="success">
        <th width="100px">ID</th>
        <th width="280px">Title</th>
        <th>Author</th>
        <th width="500px">Content</th>
        <th width="150px">Operate</th>
    </tr>
    <c:forEach var="note" items="${requestScope.page.notes}" varStatus="status">
    <tr>
        <td>${status.count}
        </td>
        <td>${note.title}
        </td>
        <td>${note.author}
        </td>
        <td>${note.content}
        </td>
        <td><a href="javascript:deleteNote(${note.id});"><img src="../images/delete.png" alt="" title="删除"></a>
           &nbsp;&nbsp;
            <a href="${pageContext.request.contextPath}/findNoteByIdServlet?id=${note.id}"><img src="../images/modify.png" alt="" title="修改"></a>
        </td>
    </tr>
    </c:forEach>
    <tr>
        <td colspan="5">
            <div style="float: right">
                <c:set var="p" value="${requestScope.page}"></c:set>
                <c:choose>
                    <c:when test="${p.currentPage==1 && p.currentPage==p.totalPage}">
                        <a href="">首页</a>
                        <a href="">上一页</a>
                        <a href="">下一页</a>
                        <a href="">尾页</a>
                    </c:when>
                    <c:when test="${p.currentPage==p.totalPage}">
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=1&title=${condition.title[0]}&author=${condition.author[0]}">首页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.currentPage-1}&title=${condition.title[0]}&author=${condition.author[0]}">上一页</a>
                <a href="">下一页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.totalPage}&title=${condition.title[0]}&author=${condition.author[0]}">尾页</a>
                </c:when>
                    <c:when test="${p.currentPage==1}">
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=1&title=${condition.title[0]}&author=${condition.author[0]}">首页</a>
                <a href="">上一页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.currentPage+1}&title=${condition.title[0]}&author=${condition.author[0]}">下一页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.totalPage}&title=${condition.title[0]}&author=${condition.author[0]}">尾页</a>
                </c:when>
                   <c:otherwise>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=1&title=${condition.title[0]}&author=${condition.author[0]}">首页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.currentPage-1}&title=${condition.title[0]}&author=${condition.author[0]}">上一页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.currentPage+1}&title=${condition.title[0]}&author=${condition.author[0]}">下一页</a>
                <a href="${pageContext.request.contextPath}/QueryNoteByPageServlet?currentPage=${p.totalPage}&title=${condition.title[0]}&author=${condition.author[0]}">尾页</a>
                </c:otherwise>
                </c:choose>
                <%
                    Page pp = (Page) request.getAttribute("page");
                %>
                <select name="currentPage" id="Select" onchange="window.location=this.value">
                    <%for (int i = 1; i <= pp.getTotalPage(); i++) {%>
                    <option value="/QueryNoteByPageServlet?currentPage=<%=i%>&title=${condition.title[0]}&author=${condition.author[0]}"
                            <%=(pp.getCurrentPage() == +i) ? "selected='selected'" : ""%>>
                        <%=i%>/${requestScope.page.totalPage}
                    </option>
                    <%}%>
                </select><br>
                第${requestScope.page.currentPage}页,共${requestScope.page.totalPage}页,
                ${requestScope.page.totalCount}条数据
            </div>
        </td>
    </tr>
</table>
<script>
    function selectPage() {
        var num = $("#select").val();
        window.location.href = "/QueryNoteByPageServlet?currentPage=" + num;
    }
</script>
</body>
</html>
